package com.htsk.city.services.core.entity;


import lombok.Data;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author：mjiaxing
 * @CreateTime：2023-04-21
 * @Description：分页信息体
 * @Version：1.0.0
 */
@Data
public class PageInfo<T,F> {
    private Integer page;
    private Integer size;
    private Long total;

    private Integer totalPage;
    private List<T> data;

    public PageInfo(){}

    public PageInfo(Pageable pageable, Page<F> pageInfo, ObjectTrans<T,F> objectTrans){
        this.page= pageable.getPageNumber()+1;
        this.size=pageable.getPageSize();
        this.total=pageInfo.getTotalElements();
        this.totalPage=pageInfo.getTotalPages();
        this.data=pageInfo.getContent().stream().map(objectTrans::tans).collect(Collectors.toList());
    }

    public PageInfo(long total, List<F> data, ObjectTrans<T,F> objectTrans){
        this.total=total;
        this.data=data.stream().map(objectTrans::tans).collect(Collectors.toList());
    }
}
